using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using LS.UnityExtensions.Editor;

namespace LS.GameKit.Editor
{
    [CustomEditor(typeof(TransformerBehaviour))]
    public class TransformerBehaviourInspector : InspectorBase
    {
        protected SerializedProperty m_LoopType;
        protected SerializedProperty m_Duration;
        protected SerializedProperty m_AccelCurve;
        protected SerializedProperty m_Activate;
        protected SerializedProperty m_OnStart;
        protected SerializedProperty m_OnStop;
        protected SerializedProperty m_OnDeltaPosition;
        protected SerializedProperty m_OnPositionChanged;
        protected SerializedProperty m_PreviewPosition;

        protected override void OnEnable()
        {
            base.OnEnable();
            m_LoopType = serializedObject.FindProperty("loopType");
            m_Duration = serializedObject.FindProperty("duration");
            m_AccelCurve = serializedObject.FindProperty("accelCurve");
            m_Activate = serializedObject.FindProperty("m_Activate");
            m_OnStart = serializedObject.FindProperty("OnStart");
            m_OnStop = serializedObject.FindProperty("OnStop");
            m_OnDeltaPosition = serializedObject.FindProperty("OnDeltaPosition");
            m_OnPositionChanged = serializedObject.FindProperty("OnPositionChanged");
            m_PreviewPosition = serializedObject.FindProperty("previewPosition");
        }

        protected override void OnDisable()
        {
            //var pt = target as TransformerBehaviour;
            //pt.PerformTransform(0);
        }

        public override void DrawInspectorItems()
        {
            base.DrawInspectorItems();
            EditorGUILayout.PropertyField(m_LoopType);
            EditorGUILayout.PropertyField(m_Duration);
            EditorGUILayout.PropertyField(m_AccelCurve);
            EditorGUILayout.PropertyField(m_Activate);
            EditorGUILayout.PropertyField(m_OnStart);
            EditorGUILayout.PropertyField(m_OnStop);
            EditorGUILayout.PropertyField(m_OnDeltaPosition);
            EditorGUILayout.PropertyField(m_OnPositionChanged);
            EditorGUILayout.PropertyField(m_PreviewPosition);
        }

        public override void OnPropertyValueChanged()
        {
            //var pt = target as TransformerBehaviour;
            //pt.PerformTransform(pt.previewPosition);
        }

        public static void PointSelectPositionField(SerializedProperty positionProperty,System.Func<Vector3> pick)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(positionProperty);
            if (GUILayout.Button("Pick",GUILayout.Width(50)))
            {
                positionProperty.vector3Value = pick();
            }
            EditorGUILayout.EndHorizontal();
        }
    }
}
